﻿<UserControl x:Class="WhiteFlow.DevTrackingTool.UI.Views.WorksheetView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:wfControls="clr-namespace:WhiteFlow.Wpf.Controls.Common;assembly=WhiteFlow.Wpf.Controls"
             xmlns:controls="clr-namespace:WhiteFlow.DevTrackingTool.UI.Controls"
             xmlns:views="clr-namespace:WhiteFlow.DevTrackingTool.UI.Views"
             xmlns:converters="clr-namespace:WhiteFlow.DevTrackingTool.UI.Converters"
             mc:Ignorable="d" 
             d:DesignHeight="400" 
             d:DesignWidth="600">
    
    <UserControl.Resources>
        <converters:DateTimeConverter x:Key="DateTimeConverter" />
        <converters:IsNullToBooleanConverter x:Key="IsNullToBooleanConverter" />
    </UserControl.Resources>

    <UserControl.Style>
        <Style>
            <Style.Triggers>
                <DataTrigger Binding="{Binding}" Value="{x:Null}">
                    <Setter Property="Control.Visibility" Value="Collapsed" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Style>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        
        <StackPanel Name="CalendarPanel" Panel.ZIndex="2" Orientation="Vertical">
            <Border Name="Calendar" Visibility="Collapsed" Height="0" 
                    BorderThickness="1,1,1,0"
                    BorderBrush="{StaticResource ResourceKey=ContentsBgBrush}"
                    Background="{StaticResource ResourceKey=CalendarAreaBgBrush}">
                <DockPanel LastChildFill="True">
                    <Border DockPanel.Dock="Top"
                            Background="White" 
                            Padding="0,10,0,10">
                        <TextBlock Text="Calendar"
                                   Margin="20,0,0,0" 
                                   FontSize="50" 
                                   Foreground="{StaticResource ResourceKey=BlueFgBrush}" 
                                   FontFamily="/WhiteFlow.DevTrackingTool.UI;Component/Resources/Fonts/#BIRTH OF A HERO" />
                    </Border>

                    <controls:TrackingCalendar x:Name="TrackingCalendar" 
                                               Language="en-US"
                                               TrackingSource="{Binding Path=Worksheet}"
                                               SelectedDate="{Binding Path=SelectedDay, Mode=TwoWay}" />
                </DockPanel>
            </Border>

            <Border Name="CalendarTab"
                    Background="{StaticResource ResourceKey=ContentsBgBrush}"
                    CornerRadius="0,0,6,6" 
                    Padding="0,5,0,5"
                    VerticalAlignment="Top">
                
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="auto" />
                    </Grid.ColumnDefinitions>

                    <Button Grid.Column="0" 
                            Cursor="Hand"
                            Margin="6,0,0,0"
                            Background="Transparent"
                            ToolTip="Select Previous Day"
                            Command="{Binding Path=SelectPreviousDayCommand}"
                            Style="{StaticResource ResourceKey=ShapelessButtonStyle}">
                        <Button.Content>
                            <wfControls:Bitmap Source="/WhiteFlow.DevTrackingTool.UI;Component/Resources/Icons/Calendar/previous_gray.png" />
                        </Button.Content>
                    </Button>
                    
                    <Border Name="SelectedDayBorder" 
                            Grid.Column="1"
                            Background="{StaticResource ResourceKey=ContentsBgBrush}"
                            Cursor="Hand"
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            ToolTip="Show Calendar">
                        <StackPanel Orientation="Horizontal">
                            <wfControls:Bitmap Source="pack://application:,,,/WhiteFlow.DevTrackingTool.UI;Component/Resources/Images/calendar_view_month.png" />
                            <TextBlock Text="{Binding Path=SelectedDate, ElementName=TrackingCalendar, TargetNullValue='(Select day)', Converter={StaticResource ResourceKey=DateTimeConverter}}" 
                                   Margin="10,0,0,0"
                                   Foreground="White"
                                   FontFamily="/WhiteFlow.DevTrackingTool.UI;Component/Resources/Fonts/#BIRTH OF A HERO"
                                   FontSize="25"
                                   VerticalAlignment="Center" />
                        </StackPanel>
                    </Border>

                    <Button Grid.Column="2"
                            Cursor="Hand"
                            Margin="0,0,6,0"
                            Background="Transparent"
                            ToolTip="Select Next Day"
                            Command="{Binding Path=SelectNextDayCommand}"
                            Style="{StaticResource ResourceKey=ShapelessButtonStyle}">
                        <Button.Content>
                            <wfControls:Bitmap Source="/WhiteFlow.DevTrackingTool.UI;Component/Resources/Icons/Calendar/next_gray.png" />
                        </Button.Content>
                    </Button>
                </Grid>
            
            </Border>
        </StackPanel>

        <TabControl Name="WsTabControl" 
                    Panel.ZIndex="1" 
                    Margin="0,50,0,0"
                    SelectedIndex="{Binding Path=SelectedWorksheetTab, Mode=TwoWay}"
                    Style="{StaticResource ResourceKey=WsTabControlStyle}">
            <TabControl.Resources>
                <Style x:Key="CollapsedIfDayHasNotTracking" TargetType="{x:Type TabItem}" BasedOn="{StaticResource ResourceKey=WsTabItemStyle}">
                    <Setter Property="OverridesDefaultStyle" Value="False" />

                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Path=SelectedTrackingDay, Mode=OneWay, Converter={StaticResource ResourceKey=IsNullToBooleanConverter}}" Value="True">
                            <Setter Property="Visibility" Value="Collapsed" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </TabControl.Resources>
            
            <TabItem>
                <TabItem.Header>
                    <Border ToolTip="Tasks">
                        <wfControls:Bitmap Source="/WhiteFlow.DevTrackingTool.UI;Component/Resources/Images/document_todo.png" />
                    </Border>
                </TabItem.Header>

                <views:TasksListView DataContext="{Binding Path=TasksListViewModel}" />
            </TabItem>
            <!--<TabItem>
                <TabItem.Header>
                    <Border ToolTip="Customers">
                        <wfControls:Bitmap Source="/WhiteFlow.DevTrackingTool.UI;Component/Resources/Icons/Application/32x32/group.png" />
                    </Border>
                </TabItem.Header>

                <views:CustomersListView DataContext="{Binding Path=CustomersListViewModel}" />
            </TabItem>
            <TabItem>
                <TabItem.Header>
                    <Border ToolTip="Projects">
                        <wfControls:Bitmap Source="/WhiteFlow.DevTrackingTool.UI;Component/Resources/Icons/Application/32x32/file_manager.png" />
                    </Border>
                </TabItem.Header>

                <views:ProjectsListView DataContext="{Binding Path=ProjectsListViewModel}" />
            </TabItem>-->
            <TabItem Style="{StaticResource ResourceKey=CollapsedIfDayHasNotTracking}">
                <TabItem.Header>
                    <Border ToolTip="Expenses">
                        <wfControls:Bitmap Source="/WhiteFlow.DevTrackingTool.UI;Component/Resources/Images/Report.png" />
                    </Border>
                </TabItem.Header>

                <views:ExpensesReportView DataContext="{Binding Path=ExpensesReportViewModel}" />
            </TabItem>
            <TabItem>
                <TabItem.Header>
                    <Border ToolTip="Stats">
                        <wfControls:Bitmap Source="/WhiteFlow.DevTrackingTool.UI;Component/Resources/Images/chart_curve.png" />
                    </Border>
                </TabItem.Header>

                <views:StatsView DataContext="{Binding Path=StatsViewModel}" />
            </TabItem>
        </TabControl>
    </Grid>
    
    <UserControl.Triggers>
        <EventTrigger RoutedEvent="MouseDown" SourceName="SelectedDayBorder">
            <BeginStoryboard>
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Calendar" Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}" />
                    </ObjectAnimationUsingKeyFrames>
                    <DoubleAnimation BeginTime="00:00:00.000" 
                                     Storyboard.TargetName="Calendar"
                                     Storyboard.TargetProperty="Height"
                                     Duration="00:00:00.400"
                                     To="{Binding ElementName=WsTabControl, Path=ActualHeight}">
                        <DoubleAnimation.EasingFunction>
                            <ElasticEase Oscillations="1" EasingMode="EaseOut" />
                        </DoubleAnimation.EasingFunction>
                    </DoubleAnimation>
                    <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="WsTabControl" Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Hidden}" />
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
        <EventTrigger RoutedEvent="MouseLeave" SourceName="CalendarPanel">
            <BeginStoryboard>
                <Storyboard Storyboard.TargetName="Calendar">
                    <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Collapsed}" />
                    </ObjectAnimationUsingKeyFrames>
                    <DoubleAnimation BeginTime="00:00:00.000" 
                                     Storyboard.TargetProperty="Height" 
                                     To="0" />
                    <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="WsTabControl" Storyboard.TargetProperty="Visibility">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00" Value="{x:Static Visibility.Visible}" />
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </UserControl.Triggers>

</UserControl>